﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CsvHelper;
using UnityEngine;

public class CharacterLevelConfigItem
{
    public int id;
    public string name;
    public int level;
    public int exAdd;
    public int levelUp = 100;
}

public class CharacterLevelConfig : ConfigBase<CharacterLevelConfig>
{
    public const string PATH = "config/LevelConfig";
    protected Dictionary<int, CharacterLevelConfigItem> m_Items;

    public CharacterLevelConfig()
    {
    }

    protected override string GetConfigPath()
    {
        return PATH;
    }

    protected override void OnCSVLoad(CsvReader csv)
    {
        m_Items = new Dictionary<int, CharacterLevelConfigItem>();
        csv.Read();
        csv.ReadHeader();
        while (csv.Read())
        {
            var item = new CharacterLevelConfigItem();
            item.id = csv.GetField<int>("id");
            item.name = csv.GetField<string>("name");
            item.level = csv.GetField<int>("level");
            item.exAdd = csv.GetField<int>("exAdd");
            m_Items[item.id] = item;
            Debug.Log("[CharacterLevelConfig][OnCSVLoad] Load CSV  " + item);
        }
    }

    public CharacterLevelConfigItem GetItem(int id)
    {
        if (m_Items.ContainsKey(id))
        {
            return m_Items[id];
        }
        return null;
    }
}
